
<!DOCTYPE html>
<html lang="zh-Hans" class="loading">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>gulp配置及使用 - 默默默默燃</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="google" content="notranslate" />
    <meta name="keywords" content="TriDiamond Obsidian,"> 
    <meta name="description" content="一枚前端搬砖队队员的记录册,gulp 入门指南1.全局安装 gulp：1$ npm install --global gulp
2.作为项目的开发依赖（devDependencies）安装：1$ npm install --s,"> 
    <meta name="author" content="张白告丶"> 
    <link rel="alternative" href="atom.xml" title="默默默默燃" type="application/atom+xml"> 
    <link rel="icon" href="/img/favicon.png"> 
    <link href="https://fonts.loli.net/css?family=Roboto+Mono|Rubik&display=swap" rel="stylesheet">
    
<link rel="stylesheet" href="//at.alicdn.com/t/font_1429596_nzgqgvnmkjb.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/animate.css/3.7.2/animate.min.css">

    
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/css/share.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/codemirror.min.css">

    
<link rel="stylesheet" href="//cdn.bootcss.com/codemirror/5.48.4/theme/dracula.css">

    
<link rel="stylesheet" href="/css/obsidian.css">

    
<link rel="stylesheet" href="/css/ball-atom.min.css">

<meta name="generator" content="Hexo 4.2.0"></head>


<body class="loading">
    <div class="loader">
        <div class="la-ball-atom la-2x">
            <div></div>
            <div></div>
            <div></div>
            <div></div>
        </div>
    </div>
    <span id="config-title" style="display:none">默默默默燃</span>
    <div id="loader"></div>
    <div id="single">
    <div class="scrollbar gradient-bg-rev"></div>
<div id="top" style="display: block;">
    <div class="bar" style="width: 0;"></div>
    <div class="navigation animated fadeIn fast delay-1s">
        <img id="home-icon" class="icon-home" src="/img/favicon.png" alt="" data-url="https://zhanghao-web.github.io">
        <div id="play-icon" title="Play/Pause" class="iconfont icon-play"></div>
        <h3 class="subtitle">gulp配置及使用</h3>
        <div class="social">
            <!--        <div class="like-icon">-->
            <!--            <a href="javascript:;" class="likeThis active"><span class="icon-like"></span><span class="count">76</span></a>-->
            <!--        </div>-->
            <div>
                <div class="share">
                    
                        <a href="javascript:;" class="iconfont icon-share1"></a>
                        <div class="share-component-cc" data-disabled="facebook,douban,linkedin,diandian,tencent,google"></div>
                    
                </div>
            </div>
        </div>
    </div>
</div>

    <div class="section">
        <div class=article-header-wrapper>
    <div class="article-header">
        <div class="article-cover animated fadeIn" style="
            animation-delay: 600ms;
            animation-duration: 1.2s;
            background-image: 
                radial-gradient(ellipse closest-side, rgba(0, 0, 0, 0.65), #100e17),
                url(/img/cover.jpg) ">
        </div>
        <div class="else">
            <p class="animated fadeInDown">
                
                <a href="/categories/Tools"><b>「
                    </b>TOOLS<b> 」</b></a>
                
                February 24, 2018
            </p>
            <h3 class="post-title animated fadeInDown"><a href="/2018/02/24/Tools/gulp%E9%85%8D%E7%BD%AE%E5%8F%8A%E4%BD%BF%E7%94%A8/" title="gulp配置及使用" class="">gulp配置及使用</a>
            </h3>
            
            <p class="post-count animated fadeInDown">
                
                <span>
                    <b class="iconfont icon-text2"></b> <i>Words count</i>
                    27k
                </span>
                
                
                <span>
                    <b class="iconfont icon-timer__s"></b> <i>Reading time</i>
                    25 mins.
                </span>
                
                
                
                <span id="busuanzi_container_page_pv">
                    <b class="iconfont icon-read"></b> <i>Read count</i>
                    <span id="busuanzi_value_page_pv">0</span>
                </span>
                
            </p>
            
            
            <ul class="animated fadeInDown post-tags-list" itemprop="keywords"><li class="animated fadeInDown post-tags-list-item"><a class="animated fadeInDown post-tags-list-link" href="/tags/Gulp/" rel="tag">Gulp</a></li></ul>
            
        </div>
    </div>
</div>

<div class="screen-gradient-after">
    <div class="screen-gradient-content">
        <div class="screen-gradient-content-inside">
            <div class="bold-underline-links screen-gradient-sponsor">
                <p>
                    <span class="animated fadeIn delay-1s"></span>
                </p>
            </div>
        </div>
    </div>
</div>

<div class="article">
    <div class='main'>
        <div class="content markdown animated fadeIn">
            <h1 id="gulp-入门指南"><a href="#gulp-入门指南" class="headerlink" title="gulp 入门指南"></a>gulp 入门指南</h1><h2 id="1-全局安装-gulp："><a href="#1-全局安装-gulp：" class="headerlink" title="1.全局安装 gulp："></a>1.全局安装 gulp：</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install --global gulp</span><br></pre></td></tr></table></figure>
<h2 id="2-作为项目的开发依赖（devDependencies）安装："><a href="#2-作为项目的开发依赖（devDependencies）安装：" class="headerlink" title="2.作为项目的开发依赖（devDependencies）安装："></a>2.作为项目的开发依赖（devDependencies）安装：</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ npm install --save-dev gulp</span><br></pre></td></tr></table></figure>
<h2 id="3-在项目根目录下创建一个名为-gulpfile-js-的文件："><a href="#3-在项目根目录下创建一个名为-gulpfile-js-的文件：" class="headerlink" title="3. 在项目根目录下创建一个名为 gulpfile.js 的文件："></a>3. 在项目根目录下创建一个名为 gulpfile.js 的文件：</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">var</span> gulp = <span class="built_in">require</span>(<span class="string">'gulp'</span>);</span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'default'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">  <span class="comment">// 将你的默认的任务代码放在这</span></span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h2 id="4-运行-gulp："><a href="#4-运行-gulp：" class="headerlink" title="4. 运行 gulp："></a>4. 运行 gulp：</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ gulp</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<p><strong>五个gulp命令</strong>:</p>
<blockquote>
<p>gulp.task(name[, deps], fn) 定义任务  name：任务名称 deps：依赖任务名称 fn：回调函数<br>gulp.run(tasks…)：尽可能多的并行运行多个task<br>gulp.watch(glob, fn)：当glob内容发生改变时，执行fn<br>gulp.src(glob)：置需要处理的文件的路径，可以是多个文件以数组的形式，也可以是正则<br>gulp.dest(path[, options])：设置生成文件的路径</p>
</blockquote>
<h2 id="package-json文件"><a href="#package-json文件" class="headerlink" title="package.json文件"></a><strong>package.json文件</strong></h2><figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"name"</span>: <span class="string">"yunbaodan"</span>,</span><br><span class="line">  <span class="attr">"version"</span>: <span class="string">"1.0.0"</span>,</span><br><span class="line">  <span class="attr">"description"</span>: <span class="string">"2.0升级"</span>,</span><br><span class="line">  <span class="attr">"main"</span>: <span class="string">"gulpfile.js"</span>,</span><br><span class="line">  <span class="attr">"scripts"</span>: &#123;</span><br><span class="line">    <span class="attr">"test"</span>: <span class="string">"echo \"Error: no test specified\" &amp;&amp; exit 1"</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="attr">"author"</span>: <span class="string">"zhang"</span>,</span><br><span class="line">  <span class="attr">"license"</span>: <span class="string">"ISC"</span>,</span><br><span class="line">  <span class="attr">"devDependencies"</span>: &#123;</span><br><span class="line">    <span class="attr">"del"</span>: <span class="string">"^3.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp"</span>: <span class="string">"^3.9.1"</span>,</span><br><span class="line">    <span class="attr">"gulp-autoprefixer"</span>: <span class="string">"^4.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-cache"</span>: <span class="string">"^1.0.1"</span>,</span><br><span class="line">    <span class="attr">"gulp-clean"</span>: <span class="string">"^0.3.2"</span>,</span><br><span class="line">    <span class="attr">"gulp-concat"</span>: <span class="string">"^2.6.1"</span>,</span><br><span class="line">    <span class="attr">"gulp-gh-pages"</span>: <span class="string">"^0.5.4"</span>,</span><br><span class="line">    <span class="attr">"gulp-htmlmin"</span>: <span class="string">"^3.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-imagemin"</span>: <span class="string">"^4.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-jshint"</span>: <span class="string">"^2.0.4"</span>,</span><br><span class="line">    <span class="attr">"gulp-less"</span>: <span class="string">"^3.3.2"</span>,</span><br><span class="line">    <span class="attr">"gulp-livereload"</span>: <span class="string">"^3.8.1"</span>,</span><br><span class="line">    <span class="attr">"gulp-minify-css"</span>: <span class="string">"^1.2.4"</span>,</span><br><span class="line">    <span class="attr">"gulp-notify"</span>: <span class="string">"^3.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-postcss"</span>: <span class="string">"^7.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-rename"</span>: <span class="string">"^1.2.2"</span>,</span><br><span class="line">    <span class="attr">"gulp-ruby-sass"</span>: <span class="string">"^2.1.1"</span>,</span><br><span class="line">    <span class="attr">"gulp-file-include"</span>: <span class="string">"^2.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-sass"</span>: <span class="string">"^3.1.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-uglify"</span>: <span class="string">"^3.0.0"</span>,</span><br><span class="line">    <span class="attr">"gulp-webserver"</span>: <span class="string">"^0.9.1"</span>,</span><br><span class="line">    <span class="attr">"jshint"</span>: <span class="string">"^2.9.5"</span>,</span><br><span class="line">    <span class="attr">"postcss-px-to-viewport"</span>: <span class="string">"^0.0.3"</span>,</span><br><span class="line">    <span class="attr">"postcss-write-svg"</span>: <span class="string">"jonathantneal/postcss-write-svg"</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="gulpfile-js-配置"><a href="#gulpfile-js-配置" class="headerlink" title="gulpfile.js 配置"></a>gulpfile.js 配置</h2><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * Created by mac on 2017/11/9.</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">//导入工具包 require('node_modules里对应模块')</span></span><br><span class="line"><span class="keyword">var</span> gulp = <span class="built_in">require</span>(<span class="string">'gulp'</span>),</span><br><span class="line">    postcss = <span class="built_in">require</span>(<span class="string">'gulp-postcss'</span>),</span><br><span class="line">    pxtoviewport = <span class="built_in">require</span>(<span class="string">'postcss-px-to-viewport'</span>),<span class="comment">//将px单位换位vw单位</span></span><br><span class="line">    sass = <span class="built_in">require</span>(<span class="string">'gulp-sass'</span>),<span class="comment">// CSS预处理/Sass编译</span></span><br><span class="line">    autoprefixer = <span class="built_in">require</span>(<span class="string">'gulp-autoprefixer'</span>),<span class="comment">//添加前缀</span></span><br><span class="line">    minifycss = <span class="built_in">require</span>(<span class="string">'gulp-minify-css'</span>),<span class="comment">//添加css压缩文件</span></span><br><span class="line">    jshint = <span class="built_in">require</span>(<span class="string">'gulp-jshint'</span>),<span class="comment">//js代码校正</span></span><br><span class="line">    uglify = <span class="built_in">require</span>(<span class="string">'gulp-uglify'</span>),<span class="comment">//js代码压缩</span></span><br><span class="line">    imagemin = <span class="built_in">require</span>(<span class="string">'gulp-imagemin'</span>),<span class="comment">//图片压缩</span></span><br><span class="line">    rename = <span class="built_in">require</span>(<span class="string">'gulp-rename'</span>),<span class="comment">//重命名</span></span><br><span class="line">    clean = <span class="built_in">require</span>(<span class="string">'gulp-clean'</span>),<span class="comment">//清除原来文件</span></span><br><span class="line">    concat = <span class="built_in">require</span>(<span class="string">'gulp-concat'</span>),<span class="comment">//合并文件</span></span><br><span class="line">    notify = <span class="built_in">require</span>(<span class="string">'gulp-notify'</span>),<span class="comment">//处理报错</span></span><br><span class="line">    cache = <span class="built_in">require</span>(<span class="string">'gulp-cache'</span>),<span class="comment">//文件对比</span></span><br><span class="line">    livereload = <span class="built_in">require</span>(<span class="string">'gulp-livereload'</span>),<span class="comment">//监听文件发生变化，浏览器自动刷新</span></span><br><span class="line">    webserver = <span class="built_in">require</span>(<span class="string">'gulp-webserver'</span>),<span class="comment">//开启服务器</span></span><br><span class="line">    ghPages = <span class="built_in">require</span>(<span class="string">'gulp-gh-pages'</span>),<span class="comment">//README.md编译成html</span></span><br><span class="line">    htmlmin = <span class="built_in">require</span>(<span class="string">'gulp-htmlmin'</span>),<span class="comment">//html压缩</span></span><br><span class="line">    fileinclude  = <span class="built_in">require</span>(<span class="string">'gulp-file-include'</span>);<span class="comment">//html模板引擎</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 样式</span></span><br><span class="line">gulp.task(<span class="string">'styles'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> processors = [</span><br><span class="line">        pxtoviewport(&#123;</span><br><span class="line">            viewportWidth: <span class="number">375</span>,</span><br><span class="line">            viewportUnit: <span class="string">'vw'</span></span><br><span class="line">        &#125;)</span><br><span class="line">    ];</span><br><span class="line">    <span class="keyword">return</span> gulp.src(<span class="string">'src/styles/*.scss'</span>)</span><br><span class="line">        .pipe(sass(&#123; <span class="attr">style</span>: <span class="string">'expanded'</span>, &#125;))</span><br><span class="line">        .pipe(autoprefixer(<span class="string">'last 2 version'</span>, <span class="string">'safari 5'</span>, <span class="string">'ie 8'</span>, <span class="string">'ie 9'</span>, <span class="string">'opera 12.1'</span>, <span class="string">'ios 6'</span>, <span class="string">'android 4'</span>))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/styles'</span>))</span><br><span class="line">        .pipe(rename(&#123; <span class="attr">suffix</span>: <span class="string">'.min'</span> &#125;))</span><br><span class="line">        .pipe(minifycss())</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/styles'</span>))</span><br><span class="line">        .pipe(notify(&#123; <span class="attr">message</span>: <span class="string">'Styles task complete'</span> &#125;))</span><br><span class="line">        .pipe(postcss(processors))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/styles'</span>))</span><br><span class="line">        .pipe(</span><br><span class="line">            postcss([</span><br><span class="line">                <span class="built_in">require</span>(<span class="string">'postcss-write-svg'</span>)(&#123; <span class="comment">/* options */</span> &#125;)</span><br><span class="line">            ])</span><br><span class="line">        ).pipe(</span><br><span class="line">            gulp.dest(<span class="string">'dist/styles'</span>)</span><br><span class="line">        );</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// js</span></span><br><span class="line">gulp.task(<span class="string">'scripts'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src(<span class="string">'src/scripts/*.js'</span>)</span><br><span class="line">        .pipe(jshint.reporter(<span class="string">'default'</span>))<span class="comment">//检测js代码错误</span></span><br><span class="line">        .on(<span class="string">'error'</span>, <span class="function"><span class="keyword">function</span> (<span class="params">err</span>) </span>&#123;</span><br><span class="line">            <span class="built_in">console</span>.error(<span class="string">'Error!'</span>, err.message); <span class="comment">// 显示错误信息</span></span><br><span class="line">        &#125;)</span><br><span class="line">        .pipe(rename(&#123; <span class="attr">suffix</span>: <span class="string">'.min'</span> &#125;))<span class="comment">// 重命名</span></span><br><span class="line">        .pipe(uglify())</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/scripts'</span>))</span><br><span class="line">        .pipe(notify(&#123; <span class="attr">message</span>: <span class="string">'Scripts task complete'</span> &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 图片</span></span><br><span class="line">gulp.task(<span class="string">'images'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src(<span class="string">'src/images/*'</span>)</span><br><span class="line">        .pipe(cache(imagemin(&#123; <span class="attr">optimizationLevel</span>: <span class="number">3</span>, <span class="attr">progressive</span>: <span class="literal">true</span>, <span class="attr">interlaced</span>: <span class="literal">true</span> &#125;)))</span><br><span class="line">        <span class="comment">// .pipe(imagemin(&#123;</span></span><br><span class="line">        <span class="comment">//     progressive: true, // 无损压缩JPG图片</span></span><br><span class="line">        <span class="comment">//     svgoPlugins: [&#123;removeViewBox: false&#125;], // 不要移除svg的viewbox属性</span></span><br><span class="line">        <span class="comment">//     use: [pngquant()] // 深度压缩PNG</span></span><br><span class="line">        <span class="comment">// &#125;))</span></span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/images'</span>))</span><br><span class="line">        .pipe(notify(&#123; <span class="attr">message</span>: <span class="string">'Images task complete'</span> &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">//html</span></span><br><span class="line">gulp.task(<span class="string">'html'</span>,<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src(<span class="string">'./*.html'</span>)</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'./'</span>))</span><br><span class="line">        .pipe(notify(&#123; <span class="attr">message</span>: <span class="string">'html task complete'</span> &#125;));</span><br><span class="line">&#125;);</span><br><span class="line">gulp.task(<span class="string">'fileinclude'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">   <span class="keyword">return</span> gulp.src(<span class="string">'./*.html'</span>)</span><br><span class="line">        .pipe(fileinclude(&#123;</span><br><span class="line">            prefix: <span class="string">'@@'</span>,</span><br><span class="line">            basepath: <span class="string">'@file'</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist'</span>));</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">// 清理</span></span><br><span class="line">gulp.task(<span class="string">'clean'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src([<span class="string">'dist/styles'</span>, <span class="string">'dist/scripts'</span>, <span class="string">'dist/images'</span>], &#123;<span class="attr">read</span>: <span class="literal">false</span>&#125;)</span><br><span class="line">        .pipe(clean());</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">//自动刷新</span></span><br><span class="line">gulp.task(<span class="string">'webserver'</span>,[<span class="string">'fileinclude'</span>],<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src( <span class="string">'dist/'</span> ) <span class="comment">// 服务器目录（./代表根目录）</span></span><br><span class="line">        .pipe(webserver(&#123; <span class="comment">// 运行gulp-webserver</span></span><br><span class="line">            livereload: <span class="literal">true</span>, <span class="comment">// 启用LiveReload</span></span><br><span class="line">            open: <span class="literal">true</span> <span class="comment">// 服务器启动时自动打开网页</span></span><br><span class="line">        &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"><span class="comment">// 预设任务及监听</span></span><br><span class="line">gulp.task(<span class="string">'default'</span>, [<span class="string">'webserver'</span>], <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    gulp.run(<span class="string">'styles'</span>, <span class="string">'scripts'</span>, <span class="string">'images'</span>);</span><br><span class="line">    <span class="comment">// 看守所有.scss档</span></span><br><span class="line">    gulp.watch(<span class="string">'src/styles/*.scss'</span>, [<span class="string">'styles'</span>]);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 看守所有.js档</span></span><br><span class="line">    gulp.watch(<span class="string">'src/scripts/*.js'</span>, [<span class="string">'scripts'</span>]);</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 看守所有图片档</span></span><br><span class="line">    gulp.watch(<span class="string">'src/images/*.*'</span>, [<span class="string">'images'</span>]);</span><br><span class="line">    <span class="comment">//监听根目录下的所有html文件</span></span><br><span class="line">    gulp.watch( <span class="string">'*.html'</span>, [<span class="string">'html'</span>]); <span class="comment">// 监听根目录下所有.html文件</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'deploy'</span>, <span class="function"><span class="keyword">function</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">return</span> gulp.src(<span class="string">'./dist/**/*'</span>)</span><br><span class="line">        .pipe(ghPages());</span><br><span class="line">&#125;);</span><br><span class="line">gulp.task(<span class="string">'testhtmlmin'</span>,<span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> options = &#123;</span><br><span class="line">        removeComments:<span class="literal">true</span>,</span><br><span class="line">        collapseWhitespace:<span class="literal">true</span>,</span><br><span class="line">        collapseBooleanAttributes:<span class="literal">true</span>,</span><br><span class="line">        removeEmptyAttributes:<span class="literal">true</span>,</span><br><span class="line">        removeScriptTypeAttributes:<span class="literal">true</span>,</span><br><span class="line">        removeStyleLinkTypeAttributes:<span class="literal">true</span>,</span><br><span class="line">        minifyJs:<span class="literal">true</span>,</span><br><span class="line">        minifyCss:<span class="literal">true</span></span><br><span class="line">    &#125;</span><br><span class="line">    gulp.src(<span class="string">'lemonhotel/*.html'</span>)</span><br><span class="line">        .pipe(htmlmin(options))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'html/build'</span>))</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
            <!--[if lt IE 9]><script>document.createElement('audio');</script><![endif]-->
            <audio id="audio" loop="1" preload="auto" controls="controls"
                data-autoplay="false">
                <source type="audio/mpeg" src="">
            </audio>
            
            <ul id="audio-list" style="display:none">
                
                
                <li title='0' data-url='/statics/chengdu.mp3'></li>
                
                    
            </ul>
            
            
            
    <div id='gitalk-container' class="comment link"
        data-ae='true'
        data-ci='ec894e2b66f752e8b7fb'
        data-cs='3ccc2e92bb350688fe2c2dc2930189b62622bfb1'
        data-r='blog-comments'
        data-o='TriDiamond'
        data-a='TriDiamond'
        data-d='undefined'
    >Comments</div>


            
            
        </div>
        <div class="sidebar">
            <div class="box animated fadeInRight">
                <div class="subbox">
                    <img src="https://res.cloudinary.com/tridiamond/image/upload/v1573019751/TriDiamond_logo_ui_xeublz.jpg" height=300 width=300></img>
                    <p>张白告丶</p>
                    <span>Think like an artist, develop like an artisan</span>
                    <dl>
                        <dd><a href="https://github.com/zhanghao-web" target="_blank"><span
                                    class=" iconfont icon-github"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-twitter"></span></a></dd>
                        <dd><a href="" target="_blank"><span
                                    class=" iconfont icon-stack-overflow"></span></a></dd>
                    </dl>
                </div>
                <ul>
                    <li><a href="/">149 <p>Articles</p></a></li>
                    <li><a href="/categories">23 <p>Categories</p></a></li>
                    <li><a href="/tags">47 <p>Tags</p></a></li>
                </ul>
            </div>
            
            
            
            <div class="box sticky animated fadeInRight faster">
                <div id="toc" class="subbox">
                    <h4>Contents</h4>
                    <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#gulp-入门指南"><span class="toc-number">1.</span> <span class="toc-text">gulp 入门指南</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-全局安装-gulp："><span class="toc-number">1.1.</span> <span class="toc-text">1.全局安装 gulp：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-作为项目的开发依赖（devDependencies）安装："><span class="toc-number">1.2.</span> <span class="toc-text">2.作为项目的开发依赖（devDependencies）安装：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-在项目根目录下创建一个名为-gulpfile-js-的文件："><span class="toc-number">1.3.</span> <span class="toc-text">3. 在项目根目录下创建一个名为 gulpfile.js 的文件：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-运行-gulp："><span class="toc-number">1.4.</span> <span class="toc-text">4. 运行 gulp：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#package-json文件"><span class="toc-number">1.5.</span> <span class="toc-text">package.json文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#gulpfile-js-配置"><span class="toc-number">1.6.</span> <span class="toc-text">gulpfile.js 配置</span></a></li></ol></li></ol>
                </div>
            </div>
            
            
        </div>
    </div>
</div>

    </div>
</div>
    <div id="back-to-top" class="animated fadeIn faster">
        <div class="flow"></div>
        <span class="percentage animated fadeIn faster">0%</span>
        <span class="iconfont icon-top02 animated fadeIn faster"></span>
    </div>
</body>
<footer>
    <p class="copyright" id="copyright">
        &copy; 2020
        <span class="gradient-text">
            张白告丶
        </span>.
        Powered by <a href="http://hexo.io/" title="Hexo" target="_blank" rel="noopener">Hexo</a>
        Theme
        <span class="gradient-text">
            <a href="https://github.com/TriDiamond/hexo-theme-obsidian" title="Obsidian" target="_blank" rel="noopener">Obsidian</a>
        </span>
        <small><a href="https://github.com/TriDiamond/hexo-theme-obsidian/blob/master/CHANGELOG.md" title="v1.4.3" target="_blank" rel="noopener">v1.4.3</a></small>
    </p>
</footer>

<script type="text/javascript" src="https://cdn.bootcss.com/mathjax/2.7.6/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<script>
  MathJax.Hub.Config({
    "HTML-CSS": {
      preferredFont: "TeX",
      availableFonts: ["STIX", "TeX"],
      linebreaks: {
        automatic: true
      },
      EqnChunk: (MathJax.Hub.Browser.isMobile ? 10 : 50)
    },
    tex2jax: {
      inlineMath: [
        ["$", "$"],
        ["\\(", "\\)"]
      ],
      processEscapes: true,
      ignoreClass: "tex2jax_ignore|dno",
      skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
    },
    TeX: {
      noUndefined: {
        attributes: {
          mathcolor: "red",
          mathbackground: "#FFEEEE",
          mathsize: "90%"
        }
      },
      Macros: {
        href: "{}"
      }
    },
    messageStyle: "none"
  });
</script>
<script>
  function initialMathJax() {
    MathJax.Hub.Queue(function () {
      var all = MathJax.Hub.getAllJax(),
        i;
      // console.log(all);
      for (i = 0; i < all.length; i += 1) {
        console.log(all[i].SourceElement().parentNode)
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  }

  function reprocessMathJax() {
    if (typeof MathJax !== 'undefined') {
      MathJax.Hub.Queue(["Typeset", MathJax.Hub]);
    }
  }
</script>



    
<link rel="stylesheet" href="//cdn.bootcss.com/gitalk/1.5.0/gitalk.min.css">

    
<script src="//cdn.bootcss.com/gitalk/1.5.0/gitalk.min.js"></script>



<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="/js/plugin.js"></script>
<script src="/js/obsidian.js"></script>
<script src="/js/jquery.truncate.js"></script>
<script src="/js/search.js"></script>


<script src="//cdn.bootcss.com/typed.js/2.0.10/typed.min.js"></script>


<script src="//cdn.bootcss.com/blueimp-md5/2.12.0/js/md5.min.js"></script>


<script src="//cdnjs.cloudflare.com/ajax/libs/social-share.js/1.0.16/js/social-share.min.js"></script>


<script src="https://cdn.bootcss.com/codemirror/5.48.4/codemirror.min.js"></script>

    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/javascript/javascript.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/css/css.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/xml/xml.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/htmlmixed/htmlmixed.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/clike/clike.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/php/php.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/shell/shell.min.js"></script>


    
<script src="//cdn.bootcss.com/codemirror/5.48.4/mode/python/python.min.js"></script>




    
<script src="/js/busuanzi.min.js"></script>

    <script>
        $(document).ready(function () {
            if ($('span[id^="busuanzi_"]').length) {
                initialBusuanzi();
            }
        });
    </script>



<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.css">
<link rel="stylesheet" href="//cdn.bootcss.com/photoswipe/4.1.3/default-skin/default-skin.min.css">


<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe.min.js"></script>
<script src="//cdn.bootcss.com/photoswipe/4.1.3/photoswipe-ui-default.min.js"></script>


<!-- Root element of PhotoSwipe. Must have class pswp. -->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
    <!-- Background of PhotoSwipe. 
         It's a separate element as animating opacity is faster than rgba(). -->
    <div class="pswp__bg"></div>
    <!-- Slides wrapper with overflow:hidden. -->
    <div class="pswp__scroll-wrap">
        <!-- Container that holds slides. 
            PhotoSwipe keeps only 3 of them in the DOM to save memory.
            Don't modify these 3 pswp__item elements, data is added later on. -->
        <div class="pswp__container">
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
            <div class="pswp__item"></div>
        </div>
        <!-- Default (PhotoSwipeUI_Default) interface on top of sliding area. Can be changed. -->
        <div class="pswp__ui pswp__ui--hidden">
            <div class="pswp__top-bar">
                <!--  Controls are self-explanatory. Order can be changed. -->
                <div class="pswp__counter"></div>
                <button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
                <button class="pswp__button pswp__button--share" title="Share"></button>
                <button class="pswp__button pswp__button--fs" title="Toggle fullscreen"></button>
                <button class="pswp__button pswp__button--zoom" title="Zoom in/out"></button>
                <!-- Preloader demo http://codepen.io/dimsemenov/pen/yyBWoR -->
                <!-- element will get class pswp__preloader--active when preloader is running -->
                <div class="pswp__preloader">
                    <div class="pswp__preloader__icn">
                      <div class="pswp__preloader__cut">
                        <div class="pswp__preloader__donut"></div>
                      </div>
                    </div>
                </div>
            </div>
            <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
                <div class="pswp__share-tooltip"></div> 
            </div>
            <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)">
            </button>
            <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)">
            </button>
            <div class="pswp__caption">
                <div class="pswp__caption__center"></div>
            </div>
        </div>
    </div>
</div>



    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="//www.googletagmanager.com/gtag/js?id=UA-149874671-1"></script>
    <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());

        gtag('config', 'UA-149874671-1');
    </script>





<script>
    function initialTyped () {
        var typedTextEl = $('.typed-text');
        if (typedTextEl && typedTextEl.length > 0) {
            var typed = new Typed('.typed-text', {
                strings: ["Think like an artist, develop like an artisan", "艺术家思维去思考问题，工匠创造精神去开发"],
                typeSpeed: 90,
                loop: true,
                loopCount: Infinity,
                backSpeed: 20,
            });
        }
    }

    if ($('.article-header') && $('.article-header').length) {
        $(document).ready(function () {
            initialTyped();
        });
    }
</script>




</html>
